/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import java.util.List;
import models.Agenda_Announcement;
import models.Category;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Aster
 */
public class AnnouncementDao {
    private final Session session;
    
    public AnnouncementDao(Session session) {
        this.session = session;
    }
    
      public List<Agenda_Announcement> findAll() {
        Transaction tx = session.beginTransaction();
        List<Agenda_Announcement> list = session.createQuery("from Agenda_Announcement").list();
        tx.commit();
        return list;
    }
    
    public void save(Agenda_Announcement Announcement) {
        Transaction tx = session.beginTransaction();
        session.save(Announcement);
        tx.commit();
    }

    public void update(Agenda_Announcement Announcement) {
        Transaction tx = session.beginTransaction();
        session.update(Announcement);
        tx.commit();
    }

    public Agenda_Announcement get(int id) {
        return (Agenda_Announcement) session.get(Agenda_Announcement.class, id);
    }
    
    public void delete(Agenda_Announcement announcement) {
        Transaction tx = session.beginTransaction();
        session.delete(announcement);
        tx.commit();
    }
}
